# import sys
# import glob

# sys.path.append('gen-py')
# sys.path.insert(0, glob.glob('../../lib/py/build/lib*')[0])


from thrift import Thrift
from thrift.transport import TSocket
from thrift.server import TServer
from thrift.transport import TTransport
from thrift.protocol import TCompactProtocol
from com.hyj.thrift.data import MyPersonService
from com.hyj.thrift.data.ttypes import *
from PersonServiceImpl import MyPersonServiceImpl

if __name__ == '__main__':

    hadler=MyPersonServiceImpl()
    processor= MyPersonService.Processor(hadler)
    # 必须指定ip 不能使用localhost 这会导致java客户端可能无法连接python 服务端（Python使用TCPV6即IPV6，Java使用TCP）
    socket= TSocket.TServerSocket(host="127.0.0.1",port=9999)
    transportFac=TTransport.TFramedTransportFactory()
    protocolFac=TCompactProtocol.TCompactProtocolFactory()
    server=TServer.TSimpleServer(processor,socket,transportFac,protocolFac)

    print('Starting the server...')
    server.serve()
    print('done.')

